package Jcat.cduestcbbs.tools;

import java.io.IOException;
import java.io.UnsupportedEncodingException;

import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.Filter;

public class EncodingFilter implements Filter {

	public void destroy() {

	}

	public void doFilter(ServletRequest request, ServletResponse response,
			FilterChain chain) throws IOException, ServletException {
		request.setCharacterEncoding("GBK");
		chain.doFilter(request, response);

	}

	public void init(FilterConfig filterConfig) throws ServletException {

	}

	public static String changeStringToGBK(String o) {
		byte s[] = null;
		try {
			s = o.getBytes("ISO-8859-1");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}

		try {
			o = new String(s, "GBK");
			return o;
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		return o;

	}
}
